//
//  mySearchBar.m
//  HappyStore
//
//  Created by 陈锋 on 16/6/15.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "mySearchBar.h"

@implementation mySearchBar

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.size = CGSizeMake(235, 30);
        self.font = [UIFont systemFontOfSize:14];
        self.placeholder = @"搜索";
        // 提前在Xcode上设置图片中间拉伸
//        self.background = [UIImage imageNamed:@"搜索1"];
        self.backgroundColor = [UIColor whiteColor];
        self.returnKeyType =UIReturnKeyDone;
        self.layer.borderColor = [UIColor whiteColor].CGColor;
        self.layer.borderWidth = 1.0;
        self.layer.cornerRadius = 8.0f;
        self.layer.masksToBounds = YES;
        
        // 通过init初始化的控件大多都没有尺寸
        UIImageView *searchIcon = [[UIImageView alloc] init];
        searchIcon.image = [UIImage imageNamed:@"Search-Icon"];
//         contentMode：default is UIViewContentModeScaleToFill，要设置为UIViewContentModeCenter：使图片居中，防止图片填充整个imageView
        searchIcon.contentMode = UIViewContentModeCenter;
        searchIcon.size = CGSizeMake(30, 30);
        
        self.leftView = searchIcon;
        self.leftViewMode = UITextFieldViewModeAlways;
    }
    return self;
}

+(instancetype)searchBar
{
    return [[self alloc] init];
}
@end
